<template lang="html">
  <div class="main-page" id="store-page">
    <!-- 标题 -->
    <!-- <van-nav-bar class="main-header" title="成为美家美货会员" :left-arrow="true" :fixed="true" :z-index="11" @click-left="onClickLeft"/> -->
    <!-- <nav-bar :title="'邀请好友注册'" @goBack="onClickLeft"/> -->
    <!-- 主体内容 -->
      <div class="main-content has-header-space">
        <div class="become_vip_page_two">
          <div :class="isClient ? 'vip_number' : 'vip_number m_top'" @click="goMyfans">
            <span>您已成功邀请{{vip_total}}位好友注册开通超级会员</span>
            <div class='more'>点击查看 <span>
              <img src="../../assets/image/activity/become_vip_right.png" alt="">
            </span></div>
          </div>
          <div class="become_vip_content"></div>
          <div class="user_page_prd_content become_vip_content_prd">
            <div class="user_page_prd_list">
              <template v-for="(item, index) in prd_list">
                <div @click="continueBuy(item)" :class="item.is_boom === 1 ? 'product_content limit_product_content' : 'product_content'" :key="index">
                  <div class="vip_product_card_left" :style="{backgroundImage: 'url('+item.product_image+')'}"></div>
                  <div class="vip_product_card">
                    <div class="vip_product_card_middle">
                      <div class="vip_product_card_middle_top">
                        <p><span>¥</span>{{item.coupon_total}}</p>
                        <p>{{item.coupon_type}}</p>
                        <p>多重权益超值享受</p>
                      </div>
                      <div class="vip_product_card_middle_bottom">
                        <img src="../../assets/image/member/vip_prd_right.png" alt="">
                      </div>
                    </div>
                    <div class="vip_product_card_right">
                      <div class="vip_product_card_right_top">
                        <p>获超值商品 + {{item.rights_title}}</p>
                      </div>
                      <div class="vip_product_card_right_bottom">
                        <p><span>¥</span>{{item.product_unit_price}}</p>
                      </div>
                    </div>
                  </div>
                  <div class="vip_product_details">
                    <div class="vip_product_details_left">
                      <h3>{{item.product_short_name}}</h3>
                      <p>{{item.product_tips}}</p>
                    </div>
                    <div class="vip_product_details_right">
                      <div :class="item.is_boom === 1 ? 'limit_prd_btn' : 'become_prd_btn'">返利 ¥<span> {{item.direct_amount}}</span></div>
                    </div>
                  </div>
                  <div class="limit_prd_tips"></div>
                </div>
              </template>
            </div>
          </div>
          <div class="become_vip_content_bottom">
            <!-- <p class="tishi">注:您的好友购买的活动礼包价格越高,您可获得的返利越高</p> -->
            <p class="become_btn" @click="Share">立即邀请好友购买</p>
          </div>
        </div>
      </div>
  </div>
</template>

<script>
// import NavBar from '@/components/global/nav-bar.vue'
// import Path from '@/utils/path.js'
import Tool from '@/utils/tool.js'
import Domain from '@/utils/domain.js'

export default {
  // components: { NavBar },
  data () {
    return {
      active: '0',
      ad_list: {},
      offset_top: 0,
      user_info: {},
      isClient: false,
      vip_total: 0,
      prd_list: [],
      isVip: false
    }
  },
  created () {
    // this.getDetalis(this.$route.params.id)
    this.getProfile()
    let isClient = Tool.isClient()
    this.isClient = isClient
    this.getTeamNum()
    this.getPrdList()
  },
  mounted () {
    // window.addEventListener('scroll',this.handleScroll,true)
  },
  beforeUpdate () {
    let dom = document.getElementsByClassName('main-header')
    if (dom && dom[0]) {
      let dh = dom[0].clientHeight || dom[0].offsetHeight
      this.offset_top = dh
    }
  },

  methods: {
    handleScroll () {
      sessionStorage.setItem('vip_h', window.pageYOffset)
      console.log(window.pageYOffset)
    },
    onClickLeft () {
      this.$router.go(-1)
    },
    switchTab (e) {
      console.log(e.target.dataset.i)
      this.active = e.target.dataset.i
    },
    goMyfans () {
      this.$router.push('/merber/team?type=vip')
    },
    continueBuy (item) {
      // let isMini = sessionStorage.getItem('isMini')
      let params = '?pid=' + item.id + '&item_id=' + item.default_item_id
      // if (isMini) {
      //   window.wx.miniProgram.navigateTo({ url: '/pages/shopDetails/shopDetails' + params })
      // } else {
      //   this.$router.push('/main/shopDetails' + params)
      // }
      this.$router.push('/main/shopDetails' + params)
    },
    getProfile () {
      return new Promise((resolve, reject) => {
        this.$Axios({ url: 'profile', method: 'get' }).then((resp) => { // 请求成功
          if (resp.return_code === '0000') {
            this.user_info = resp.data.user_info
            if (resp.data.user_info.lev_code === 'COMMON_USER') {
              this.isVip = false
            } else {
              this.isVip = true
            }
          }
          resolve(resp)
        }).catch((error) => { // 请求失败
          this.$_requestInterceptor('error', error)
          reject(error)
        })
      })
    },
    getTeamNum () {
      return new Promise((resolve, reject) => {
        this.$Axios({ url: 'user_team', params: { type: 'vip' }, method: 'get' }).then((resp) => { // 请求成功
          if (resp.return_code === '0000') {
            this.vip_total = resp.data.total
          }
          resolve(resp)
        }).catch((error) => { // 请求失败
          this.$_requestInterceptor('error', error)
          reject(error)
        })
      })
    },
    getPrdList () {
      return new Promise((resolve, reject) => {
        this.$Axios({ url: 'product', params: { is_gift_bag: 1, pagesize: 1000 }, method: 'get' }).then((resp) => { // 请求成功
          if (resp.return_code === '0000') {
            this.prd_list = resp.data.list
          }
          resolve(resp)
        }).catch((error) => { // 请求失败
          this.$_requestInterceptor('error', error)
          reject(error)
        })
      })
    },
    Share () {
      var url = encodeURIComponent('pages/activity/join_vip/join_vip?invite=' + this.user_info.invite_id)
      var title = encodeURIComponent('倾情推荐！开启超级会员之旅，超值特权嗨不停。')
      var desc = encodeURIComponent('Hi，我是' + this.user_info.user_nickname + '分享一个正品购物平台给你')
      var imgurl = encodeURIComponent(Domain('/wechat/images/v4/share_vip.png'))
      window.location = 'yggshare://title=' + title + '&desc=' + desc + '&imgurl=' + imgurl + '&url=' + url
    }
  }
}
</script>
